require 'erb'

before "deploy:setup", :facebooker_config
after "deploy:update_code", "facebooker_config:symlink" 

namespace :facebooker_config do
  desc "Create facebooker config yaml in shared path" 
  task :default do
    facebooker_config = ERB.new <<-EOF
    defaults: &defaults
      api_key: #{fb_api_key}
      secret_key: #{fb_secret_key}
      canvas_page_name: #{fb_canvas_name}
      callback_url: #{fb_callback_url}
      pretty_errors: true
      set_asset_host_to_callback_url: true
 
    development:
      <<: *defaults 
    test:
      <<: *defaults
    production:
      <<: *defaults
    
    EOF

    run "mkdir -p #{shared_path}/config" 
    put facebooker_config.result, "#{shared_path}/config/facebooker.yml" 
  end

  desc "Make symlink for facebooker config yaml" 
  task :symlink do
    run "ln -nfs #{shared_path}/config/facebooker.yml #{release_path}/config/facebooker.yml" 
  end
end
